﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TTEngine
{
    public class Bars : MapObject
    {
        //constructor
        public Bars()
            : base()
        {
            BlocksMovement = true;
            Lock = new Lock(3);
            IsLocked = true;
        }

        //clone
        public override MapObject Clone()
        {
            return new Bars();
        }

        //the lock
        public Lock Lock { get; set; }

        //are they locked?
        public bool IsLocked { get; set; }

        //are they bent open?
        public bool IsBentOpen { get; set; }

        //allow them to be unlocked, bent, closed
        public override List<string> GetActionsAdjacent(Actor actor)
        {
            List<string> actions = base.GetActionsAdjacent(actor);
            if (IsLocked)
            {
                actions.Add("Bend Open");

                //if the actor has an appropriate key, allow them to unlock
                foreach (MapObject gear in actor.Gear)
                    if (gear is Key)
                    {
                        Key key = (Key)gear;
                        if (key.Code == Lock.Code)
                        {
                            actions.Add("Unlock");
                            break;
                        }
                    }
            }
            else if (!IsBentOpen)
                actions.Add("Lock");
            return actions;
        }
    }
}
